<?php
require_once BASE_PATH.'application/libraries/barcode/class/BCGFontFile.php';
require_once BASE_PATH.'application/libraries/barcode/class/BCGColor.php';
require_once BASE_PATH.'application/libraries/barcode/class/BCGDrawing.php';
require_once BASE_PATH.'application/libraries/barcode/class/BCGcode39.barcode.php';



class barcodeDAO extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    
    function generate($data = array()){
        
        $data = overwrite_array(array(
                                      "text"  => "1",
                                      "path"   => ""
                                      ),$data);
        
        $font = new BCGFontFile(BASE_PATH.'application/libraries/barcode/font/Arial.ttf', 18);
            
        $color_white = new BCGColor(0, 0, 0);
        $color_black = new BCGColor(255, 255, 255);
        
        $code = new BCGcode39(); // Or another class name from the manual
        $code->setScale(3); // Resolution
        $code->setThickness(30); // Thickness
        $code->setForegroundColor($color_black); // Color of bars
        $code->setBackgroundColor($color_white); // Color of spaces
        $code->setFont($font); // Font (or 0)
        $code->parse($data["text"]); // Text
        

        $drawing = new BCGDrawing($data["path"], $color_black);
        $drawing->setBarcode($code);
        $drawing->draw();
        $hola = $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);

        //header('Content-Type: image/png');
    }
    
}